from django.db import models


# Create your models here.
from areas.models import Areas
from users.models import User


class Address(models.Model):
    """
    用户收货地址
    """
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="addresses", verbose_name=u"用户")
    title = models.CharField(max_length=20, verbose_name=u"地址名称")
    receiver = models.CharField(max_length=20, verbose_name=u"收货人")
    province = models.ForeignKey(Areas, on_delete=models.PROTECT, verbose_name=u"省份", related_name="province")
    city = models.ForeignKey(Areas, on_delete=models.PROTECT, verbose_name=u"市", related_name="city")
    district = models.ForeignKey(Areas, on_delete=models.PROTECT, verbose_name=u"区", related_name="district")
    place = models.CharField(max_length=50, verbose_name=u"地址")
    mobile = models.CharField(max_length=11, verbose_name=u"手机")
    tel = models.CharField(max_length=20, verbose_name=u"座机号码", blank=True, null=True, default='')
    email = models.CharField(max_length=20, verbose_name=u"邮箱", blank=True, null=True, default='')
    is_default = models.BooleanField(default=False, verbose_name=u"是否默认")
    is_deleted = models.BooleanField(default=False, verbose_name=u"逻辑删除")

    class Meta:
        db_table = "tb_address"
        verbose_name = u"用户收货地址"
        verbose_name_plural = verbose_name
        ordering = ["-is_default"]
